﻿// SKNotes - a note taking and gathering tool
// Copyright (C) 2009  Stefan Kueng
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System.Windows;
using System.Windows.Controls;

namespace SKNotes.CustomControls.HtmlEditor.Control
{
    /// <summary>
    /// Interaction logic for AnchorDialogue.xaml
    /// </summary>
    public partial class AnchorDialogue : Window
    {

        private string _linkText;
        private string _url;

        public AnchorDialogue()
            : this(string.Empty)
        {
        }

        public AnchorDialogue(string linkText)
        {
            InitializeComponent();
            this._linkText = linkText;
            this.txtLinkText.Text = linkText;
        }

        /// <summary>
        /// Gets the selected link text.
        /// </summary>
        public string LinkText
        {
            get
            {
                string linkText = this._linkText;
                if (string.IsNullOrEmpty(linkText))
                {
                    linkText = this._url;
                }
                return linkText;
            }
        }

        /// <summary>
        /// Gets the selected url.
        /// </summary>
        public string Url
        {
            get { return this._url; }
        }

        private void txtUrl_TextChanged(object sender, TextChangedEventArgs e)
        {
            this.btnOK.IsEnabled = (this.txtUrl.Text.Length > 0);
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (this.txtUrl.Text.Length > 0)
            {
                this._url = this.txtUrl.Text;
                this._linkText = this.txtLinkText.Text;
                this.DialogResult = true;
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}
